<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>优惠券核销</title>
<meta name="viewport" content="width=100%, initial-scale=1.0, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="/lib/weix/style/weui.min.css">
<link rel="stylesheet" href="/css/fonts.css">
<link rel="stylesheet" href="/css/comm.css">
<link rel="stylesheet" href="/css/code_yhq_hx.css">
</head>

<body>
<div class="card__boxs">
    <div class="card__box" id="J_card__box">
        <div class="card__hd">
            <div class="card__hd-yh" id="J_youh">--</div>
            <div class="card__hd-xz th-xx_left">
                <p>单笔消费满<span id="J_manz"></span>元可使用</p>
                <p>截止<span id="J_time">---</span>(含)有效</p>
            </div>
            <div class="card__hd-ts" id="J_leix">折扣券</div>
        </div>
        <div class="card__bd">
            <div class="card__hd-tb"><i class="icon-user"></i></div>
            <div class="card__hd-xx">
                <p class="item">领券人：<span id="J_name">--</span></p>
                <p class="item">电话：<span id="J_iph">--</span></p>
                <p class="item">发券人：<span id="J_fname">--</span></p>
            </div>
        </div>
    </div>
</div>

<div class="card__czbox" id="J_hx_czbox" style="display:none;">
	<div style="padding:10px; color:#F00; font-size:12px; text-align:center;">*请开单人员扣除指定不参与优惠商品后，填写消费金额</div>
    <div class="weui-cells" style="margin:0">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <input class="weui-input" type="number" placeholder="请输入消费金额" style="text-align:center;" id="J_jine">
            </div>
        </div>
    </div>
    <div class="weui-btn-area">
        <a class="weui-btn weui-btn_primary" href="javascript:" id="J_qued">确定</a>
    </div>
</div>

<div class="weui-cells" id="J_hx_infobox" style="display:none;">
    <!--<div class="weui-cell">
        <div class="weui-cell__hd"></div>
        <div class="weui-cell__bd">
            <p>使用时间</p>
        </div>
        <div class="weui-cell__ft" id="J_sytime">---</div>
    </div>-->
    <div class="weui-cell">
        <div class="weui-cell__hd"></div>
        <div class="weui-cell__bd">
            <p>核销人</p>
        </div>
        <div class="weui-cell__ft" id="J_hxuser">---</div>
    </div>
</div>

<script src="/js/zepto.min.js"></script>
<script src="https://res.wx.qq.com/open/libs/weuijs/1.0.0/weui.min.js"></script>
<script src="/js/comm.js"></script>
<script type="text/javascript">
//初始化
function quan_info(){
	var data = {id:'${id}'};
	var url = "/customer/CouponDetail";
	$.ajax({
		type: "POST",
		dataType: 'json',
		async: false,
		contentType: "application/json; charset=utf-8",
		data: JSON.stringify(data),
		url: url,
		success: function(res){
			var datas=res.data
			if(res.code == 200){
				
				if(datas.discount_type == 0){  						//0满减 1折扣
					$('#J_leix').html('满减券')
					$('#J_youh').html('￥'+datas.discount)			//优惠
				}else if(datas.discount_type == 1){
					$('#J_leix').html('折扣券')
					$('#J_youh').html(datas.discount+'折')			//优惠
				}
				
				$('#J_ewm').html('<img src="'+datas.qrcode+'" />')	//二维码
				$('#J_manz').html(datas.full)						//满多少
				$('#J_time').html(datas.overtime)					//截止日期
				
				$('#J_name').html(datas.name)						//领券人
				$('#J_iph').html(datas.phone)						//电话
				$('#J_fname').html(datas.userName)					//发券人
				
				$('#J_hxuser').html(datas.ver_name)					//发券人
				
				
				if(datas.status==0){								//是否使用 0未核销  1过期  2已核销
					$('#J_hx_czbox').show()
					return false
				}else if(datas.status==1){							
					$('#J_card__box').append('<div class="th-info__zhang on"><i class="icon-zhang"></i><span class="z">已过期</span></div>')
					$('#J_hx_czbox').remove();
					return false
				}else if(datas.status==2){
					$('#J_card__box').append('<div class="th-info__zhang"><i class="icon-zhang"></i><span class="z">已使用</span></div>')
					$('#J_hx_czbox').remove();
					$('#J_hx_infobox').show();
					return false
				}
				
			}else{
				weui.topTips(res.msg);
			}
		},
		error: function(e){
	
		},
		complete: function(e){
		}
	});
}


$(function(){	
	quan_info() //初始化数据
	//${id}
	//-----------------------------------------------------------------------
	$(document).on('click','#J_qued',function(){
		
		var data_jine = $('#J_jine').val()
		
		if(isNaN(data_jine) || data_jine <= 0){
			weui.topTips('请填写正确的消费金额');
			return false
		}

		weui.dialog({
			title: '确定使用',
			content: '是否确认使用优惠券？',
			className: 'custom-classname',
			buttons: [{
				label: '取消',
				type: 'default',
				onClick: function () {}
			}, {
				label: '确定',
				type: 'primary',
				onClick: function () {
					
					var loading = weui.loading('数据提交中', {
						className: 'custom-classname'
					});

					var data = {id:'${id}',uid:'${uid}',sale_money:data_jine};
					var url = "/customer/verificate_coupon";
					$.ajax({
						type: "POST",
						dataType: 'json',
						async: false,
						contentType: "application/json; charset=utf-8",
						data: JSON.stringify(data),
						url: url,
						success: function(res){
							var datas=res.data
							if(res.code == 200){
								weui.toast('使用成功', {
									duration: 1500,
									className: 'custom-classname',
									callback: function(){
										quan_info() //重新加载数据
									}
								});
								
							}else{
								weui.topTips(res.msg);
							}
						},
						error: function(e){
					
						},
						complete: function(e){
							loading.hide();
						}
					});
					
				}
			}]
		});
		
		//提交成功后跳转
		//history.back(-1)
	})
});
</script>
</body>
</html>